Data Director: when and how to use "Allow Identity Insert" on a Scheduler Subjob
In this article
When Data Director (DD) replicates into a table that has an identity (AutoIncrement) column, SQL Server generates its own value for that column instead of using the value from the source. The source and destination values then drift apart, and replication can show missing records, skipped records, wrong updates or deletes, or duplicate key errors.
Enabling Allow Identity Insert on the Scheduler Subjob makes DD write the source value into the identity column.
Symptoms
Consider this setting if you see one or more of the following when replicating a table with an identity field:
- Records exist in the destination database but are not visible in the client (for example sales prices in POS or the store).
- Sales prices are not replicated or not updated, for the new pricing tables: Price List Header (7000), Price List Line (7001) and 7002.
- Violation of UNIQUE KEY constraint or Cannot insert duplicate key errors.
- Records are skipped, duplicated, or the job reports "Nothing to do".
- The Line No., Entry No. or Sequence No. value for the same record differs between source and destination.
- Pre-action or By Actions replication fails on a duplicate key.
Cause
The identity column (for example Line No. on Price List Line, or Entry No. on entry tables) auto-increments in the destination database. If the destination table was cleared and then refilled by replication, or records were inserted by DD without the setting, SQL Server assigns its own sequence. The values no longer match the source, so later updates and deletes from the source hit the wrong rows or fail.
What the setting does
The Allow Identity Insert check on the subjob sets IDENTITY_INSERT ON at the start of the SQL command and OFF at the end. The identity column is then overwritten with the value from the source instead of the local sequence. See the Microsoft documentation on SET IDENTITY_INSERT for details.
Resolution
- Verify the cause. Compare the records for the same primary key in the source and destination databases. If the identity value (for example Line No.) differs, this is the cause.
- Clear the destination table. Remove the existing data in the destination table, either with a SQL script or by running the job as Update-Add-Delete. This is important: rows that were already inserted with a wrong identity value are not corrected by simply enabling the setting.
- Enable the setting. Open the Scheduler Subjob card for the table and tick Allow Identity Insert.
- Run the replication job as normal.
- Verify that the identity values and data now match the source, and that the records show in the client.
Price List Header and Line (table, 7001)
This is the most common case. If price list lines were removed in the destination and then replicated back, the Line No. goes out of sync with the source. Apply the steps above to the subjob for Price List Line (7001), for both By Actions and Pre-Action replication.
Limitations and cautions
- The table must have an identity column.You will receive an error on the job if you enable the flag on a subjob that does not have an identity column
- Use a current Data Director build. Older builds had issues with this setting.
- The setting overwrites existing records that have the same key. For a duplicate key error on other tables, first trace the record and compare source and destination so no data is lost.
- It does not replace checking other causes, such as table field configuration or extension fields not being replicated.